<script setup lang="ts">

import Trans from "~/utils/sycm/trans";

const props = defineProps({
  data: {
    type: Array,
    default: () => []
  },
  showZs: {
    type: Boolean,
    default: false
  },
  tableName: {
    type: String,
    default: ''
  }
})
const columns = ref<any[]>([]);
const dataSource = ref<any[]>([]);
const calc = () => {
  dataSource.value = [];
  props.data?.map((item: any) => {
    dataSource.value.push({
      ...item.originData,
      platform: '全网',
    })
  })
  columns.value = [
    {
      dataIndex: 'shop',
      title: '店铺名称',
      sorter: (a: any, b: any) => a.shop.title.localeCompare(b.shop.title),
      dataType: 'shop',
      dataField: {
        shop_title: 'shop.title',
        shop_pic: 'shop.pictureUrl',
        shop_url: 'shop.shopUrl',
        b2CShop: 'shop.b2CShop',
      }
    },
    {
      dataIndex: 'tradeIndex',
      title: props.showZs ? '交易指数' : '交易金额',
      sorter: (a: any, b: any) => a.tradeIndex - b.tradeIndex,
      align: 'right',
      dataType: 'customRender',
      render: (text: any) => {
        if (props.showZs) {
          return text
        } else {
          const price = Trans.number(text);
          return (price+'').replace(/\B(?=(\d{3})+(?!\d))/g, ',');
        }
      }
    },
    {
      dataIndex: 'tradeGrowthRange',
      title: '交易增长幅度',
      sorter: (a: any, b: any) => a.tradeGrowthRange - b.tradeGrowthRange,
      align: 'right',
      dataType: 'customRender',
      render: (text: any) => {
        return (text*100).toFixed(2) + '%';
      }
    },
    {
      dataIndex: 'platform',
      title: '平台',
      sorter: (a: any, b: any) => a.platform.localeCompare(b.platform),
      align: 'right',
    }
  ];
}
calc();
watch(() => props.showZs, (val) => {
  calc();
})
</script>

<template>
  <base-table :table-name="tableName" :data-source="dataSource" :columns="columns" :scroll="{
    y:750
  }"
  >

  </base-table>
</template>

<style scoped>

</style>
